<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/29 0029
 * Time: 22:08
 */

namespace App\Http\Controllers;


use App\Jobs\TestJobs;
use Validator;
use App\Http\Requests\Member;
use Illuminate\Http\Request;
use App\Models\Member as MemberModle;
use Illuminate\Support\Facades\DB;

class memberController extends Controller
{
    public function index(Request $request){
        $list = DB::table('member')->paginate('2');
//        $m = new MemberModle();
//        $list = $m::paginate(2);
//    $list = MemberModle::paginate(2);
//        dd($list);
        return view('member.index',[
            'list' => $list,
        ]);
    }

    public function addMember(Request $request){
        return view('member.add-member');
    }

    public function saveMember(Member $request){
        // 获取通过验证的数据...
        $model = new MemberModle();
        $model->name = $request['username'];
        $model->email = $request['email'];
        $model->pwd = $request['pass'];
        $model->save();
        return response()->json(['err'=>0,'msg'=>'新增成功']);
    }

    public function getList () {

    }

    public function detail (Request $request) {
        dd($request->all());
    }


    /**
     * 逻辑树
     */
    public function logicalTree(){
        $arr = [
            '学生列表' => [
                '实现状态' => '待完成',
                '子逻辑' => [
                    [
                        'name' => '增',
                        'status' => '待完成',
                    ],
                    [
                        'name' => '删除',
                        'status' => '待完成',
                    ],
                    [
                        'name' => '改',
                        'status' => '待完成',
                    ],
                    [
                        'name' => '查询',
                        'status' => '待完成',
                    ]
                ]
            ],
            '后台登录' => [
                '实现状态' => '待完成',
                '子逻辑' => [
                    [
                        'name' => '增',
                        'status' => '待完成',
                    ],
                    [
                        'name' => '删除',
                        'status' => '待完成',
                    ],
                    [
                        'name' => '改',
                        'status' => '待完成',
                    ],
                    [
                        'name' => '查询',
                        'status' => '待完成',
                    ]
                ]
            ]
        ];
        return dd($arr);
    }

    public function test(){

        $spec_arr = array(
            20 => array('7','8','9'),
            10=>array('1','2'),
            1 => array('3','4'),

        );
        // 排序
        foreach ($spec_arr as $k => $v)
        {
            $spec_arr_sort[$k] = count($v);
        }
        asort($spec_arr_sort);
        foreach ($spec_arr_sort as $key =>$val)
        {
            $spec_arr2[$key] = $spec_arr[$key];
        }

        $clo_name = array_keys($spec_arr2);
        $spec_arr2 = combineDika($spec_arr2); //  获取 规格的 笛卡尔积


//        print_r($spec_arr2);
    }

    public function testJob(){
        dispatch(new TestJobs(['a'=>1]));
    }
}